<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../CSS/media.css">
    <style>
        .Modular {
            width: 100%;
            margin: 0px 0px 10px 0px;
            padding: 20px 0px;
            background: #fff;
        }
        .Modular>div{
            width: 80%!important;
            margin: auto;
        }
        .e{
            width: 80%;
            margin: 20px auto;
        }
        .e_left{
            width: 10%;
            position: fixed;
            top: 20px;
            background: #fff;
            box-shadow: 3px 6px 11px 0 #d4d4d4;
            padding: 10px 0px;
            height: 100%;
        }
        .e_left i{
            font-weight: normal !important;
        }
        .e_left span{
            margin-left: 10px;
        }
        .e_left ul li{
            width: 100%;
            height: 50px;
            line-height: 50px;
            padding-left: 20px;
            font-size: 15px;
            font-weight: bold;
            color: #868686;
            cursor: pointer;
            box-sizing: border-box;
        }
        .leftHandle {
            color: #1E9FFF;
            background: #b6deff;
        }
        .e_left ul li:hover{
            color: #1E9FFF;
            background: #b6deff;
        }
        .e_right {
            width: 86%;
            float: right;
        }
        .e_right .layui-tab-title{
            border-bottom-style: none;
            height: 70px;
            line-height: 70px;
            box-shadow: 1px 2px 5px 0 #f5f5f5;
        }
        .e_right .layui-tab{
            margin: 0px!important;
        }
        .e_right .layui-this{
            color: #1E9FFF!important;
        }
        .e_right .layui-this:after{
            border-bottom:0px!important;
        }
        .e_right .layui-tab-title li{
            font-size: 18px;
            font-weight: bold;
            color: #868686;
        }
        .e_right .layui-tab-content {
            padding: 0px!important;
        }
        .e_r_title{
            font-size: 20px;
            font-weight: bold;
            padding: 0px 20px 10px 0px;
            color: #868686;
            display: inline-block;
        }
        .e_r_con{
            padding: 15px 0px 20px 0px;
        }
        .e_r_con_list li{
            overflow: hidden;
            padding: 20px;
            margin-bottom: 20px;
            border-bottom: 1px #e8e8e8 solid
        }
        .e_r_con_list li:last-child{
            border: none;
        }
        .e_r_btn{
            width: 170px;
            float: right;
        }
        .e_show_type{
            display: none;
            width: 100px;
            height: 40px;
            line-height: 40px;
            color: #fff;
            text-align: center;
            background: #1E9FFF;
            position: fixed;
            right: 0px;
            top: 60px;
            z-index: 9;
            border-top-left-radius: 5px;
            border-bottom-left-radius: 5px;
        }
        .layui-tab-item{
            min-height: 150px;
            position: relative;
        }
        .e_r_tab{
            background: #fff;
            box-shadow: 3px 6px 11px 0 #d4d4d4;
            padding-bottom: 10px;
        }
        .e_r_author{
            display: inline-block;
            margin-right: 20px;
        }
        .e_r_time{
            display: inline-block;
        }

    </style>
</head>
<body style="width: 100%;padding: 0px">
<!--手机模式显示左侧类型按钮-->
<div class="e_show_type">
    <i class="layui-icon">&#x1005;</i>
    <span>选择类型</span>
</div>
<div class="e layui-form">
    <div class="e_left">
        <ul>
            <li name="app">
                <i class="layui-icon">&#xe618;</i>
                <span>应用发布请求</span>
            </li>
            <li name="mould">
                <i class="layui-icon">&#xe623;</i>
                <span>模板发布请求</span>
            </li>
            <li name="data">
                <i class="layui-icon">&#xe621;</i>
                <span>数据发布请求</span>
            </li>
            <li name="style">
                <i class="layui-icon">&#xe632;</i>
                <span>样式发布请求</span>
            </li>
            <li name="download">
                <i class="layui-icon">&#xe674;</i>
                <span>数据下载请求</span>
            </li>
        </ul>
    </div>
    <div class="e_right">
        <div class="e_r_tab">
            <div class="layui-tab layui-tab-brief" lay-filter="draft">
                <ul class="layui-tab-title">
                    <li lay-id='0' class="layui-this">待审核</li>
                    <li lay-id='1'>已通过</li>
                    <li lay-id='2'>未通过</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show inAudit">
                        <ul class="e_r_con_list"></ul>
                    </div>
                    <div class="layui-tab-item adopt">
                        <ul class="e_r_con_list"></ul>
                    </div>
                    <div class="layui-tab-item notPass">
                        <ul class="e_r_con_list"></ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="../../JS/jquery-2.0.3.js"></script>
<script src="../../layui/layui.js" charset="utf-8"></script>
<script>
    var tabHandleArr = [0];//默认待审核初始化已经请求数据
    var tabHandle = 0;
    var url = ['/app/selCheckList','/template/selCheckList','/data/selCheckList','/style/selCheckList',''];
    var flow = null;
    layui.use(['element','form','flow'], function () {
        var element = layui.element,
            form = layui.form;
            flow = layui.flow;

        //点击左侧菜单获取数据
        var param = {
            'condition': {
                'status': 0,
                'id': parent.getLocalStorage('JSXM').id
            }
        };
        element.on('tab(draft)', function(data){
            if (tabHandleArr.indexOf(data.index) === -1) {

                //获取当前操作的类型
                var pos = $('.leftHandle').index() === -1 ? 0 : $('.leftHandle').index();

                var type = ['inAudit','adopt','notPass'];
                var status = [0,1,3];
                param.condition.status = status[data.index];
                tabHandle = data.index;
                parent.getFlowDataByPost(parent.defaultUrl+url[pos],param,1,flow,getList,type[data.index]);
                tabHandleArr.push(data.index);
            }
        });

        //初始化默认显示应用数据
        parent.getFlowDataByPost(parent.defaultUrl+'/app/selCheckList',param,1,flow,getList,'inAudit',0);

        $('.e_left li').click(function () {
            //清空数据
            $('.e_r_con_list').html('');
            $('.noData').show();
            $('.layui-flow-more').remove();
            //tab页切换到第一个
            element.tabChange('draft', 0);
            tabHandleArr = [0];
            tabHandle = 0;
            leftHandleIndex = $(this).index();
            $(this).addClass('leftHandle').siblings().removeClass('leftHandle');
            //调用接口获取该类型审核中数据
            if (parent.getLocalStorage('JSXM') && parent.getLocalStorage('JSXM').id) {
                parent.getFlowDataByPost(parent.defaultUrl+url[leftHandleIndex],{"condition": {'status':0, 'id': parent.getLocalStorage('JSXM').id}},1,flow,getList,'inAudit',0)
            }
        })
    });

    var leftHandleIndex = 0;
    $(function () {
        
        //手机模式显示左侧类型按钮触发事件
        $('.e_show_type').click(function () {
            if ($('.e_left').css('display') !== 'none') {
                $(this).find('span').text('选择类型');
                $('.e_left').hide().animate({'left':'-180px'},100)
                $('.e_right').animate({'marginLeft':'0px'},100)
            } else {
                $(this).find('span').text('隐藏类型');
                $('.e_left').show().animate({'left':'0px'},100)
                $('.e_right').animate({'marginLeft':'190px'},100)
            }
        })
    })

    //获取数据生成html
    function getList(data,type,type2) {
        if (type2) {
            $('.'+type).find('.e_r_con_list').html('');
        }
        var html = ''
        for (var i = 0,l=data.length;i<l;i++) {
            var desc = data[i].desc || data[i].dataDes;
            html+='<li>\n' +
                '  <div class="e_r_title">'+data[i].name+'</div>\n' +
                '  <div class="e_r_author"><span>发布人：</span><i>'+data[i].username+'</i></div>\n' +
                '  <div class="e_r_time"><span>发布时间：</span><i>'+data[i].time+'</i></div>\n' +
                '   <div class="e_r_con">'+desc+'</div>' ;
            if (tabHandle === 0) {
                html += '  <div class="e_r_btn">\n' +
                '  <button type="button" class="layui-btn layui-btn-normal" onclick="agree('+data[i].id+',this)">同意</button>\n' +
                '  <button type="button" class="layui-btn layui-btn-normal" onclick="unagree('+data[i].id+',this)">不同意</button>\n' +
                '   </div>\n' ;
            }

            html += ' </li>'
        }
        html +=   '</div>'
        $('.'+type).find('.e_r_con_list').append(html);
    }
    
    //同意触发事件
    var checkUrl = ['/app/check','/template/check','/data/check','/style/check',''];
    var selUrl = ['/app/selAppById','/template/selTemplateById','/data/selDataById','/style/selStyleById',''];
    var updateUrl = ['/app/updateApp','/template/updateTemplate','/data/updateData','/style/updateStyle',''];
    function agree(id,obj) {
        //调用审核同意接口
        if (parent.getLocalStorage('JSXM') && parent.getLocalStorage('JSXM').id) {
            parent.ajaxPost(parent.defaultUrl+checkUrl[leftHandleIndex],{
                "groupid": 0,
                "objid": id,
                "shstatus": 1,
                "userid": parent.getLocalStorage('JSXM').id
            },function (data) {
                if (data.code === 200) {
                    layer.msg('审核通过');
                    parent.getFlowDataByPost(parent.defaultUrl+url[leftHandleIndex],{"condition": {'status':0, 'id': parent.getLocalStorage('JSXM').id}},1,flow,getList,'inAudit',1)
                } else if (data.message) {
                    layer.msg(data.message)
                }
            })
        }
    }
    
    //不同意触发事件
    function unagree(id,obj) {
        //通过id获取该样式数据
        parent.ajaxGet(parent.defaultUrl + selUrl[leftHandleIndex], {'id': id}, function (data) {
            if (data.code === 200) {
                data = data.data;
                data.status = 3;
                parent.ajaxPost(parent.defaultUrl + updateUrl[leftHandleIndex],data,function (data) {
                    if (data.code === 200) {
                        layer.msg('操作成功');
                        parent.getFlowDataByPost(parent.defaultUrl+url[leftHandleIndex],{"condition": {'status':0, 'id': parent.getLocalStorage('JSXM').id}},1,flow,getList,'inAudit',1)
                    } else if (data.message) {
                        layer.msg(data.message)
                    }
                })
            } else if (data.message) {
                layer.msg(data.message)
            }
        })
    }
</script>
</body>
</html>